package com.proxyhub.utils;

import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import org.springframework.beans.BeanUtils;
import org.springframework.cglib.beans.BeanMap;

/**
 * Created by linxsh on 2017/6/15.
 */
public class BeanUtil {
    public static DBObject convertToDBObject(Object o) {
        BeanMap beanMap = BeanMap.create(o);
        DBObject dbObject = new BasicDBObject();
        for(Object key: beanMap.keySet()) {
            Object val = beanMap.get(key);
            if(val!= null) {
                dbObject.put((String)key, val);
            }
        }
        return dbObject;
    }

}
